﻿using Beetle;
using System;

internal class Class_w : IByteConverter
{
    private byte[] _field_a = new byte[1];
    private byte[] _field_b = new byte[2];
    private byte[] _field_c = new byte[4];
    private byte[] _field_d = new byte[8];
    private ByteArraySegment _field_e;

    public byte[] GetBytes(bool value)
    {
        if (value)
        {
            this._field_a[0] = 1;
        }
        else
        {
            this._field_a[0] = 0;
        }
        return this._field_a;
    }

    public byte[] GetBytes(byte value)
    {
        this._field_a[0] = value;
        return this._field_a;
    }

    public byte[] GetBytes(char value)
    {
        return this.GetBytes((short)value);
    }

    public unsafe byte[] GetBytes(double value)
    {
        return this.GetBytes(*((long*)&value));
    }

    public unsafe byte[] GetBytes(short value)
    {
        fixed (byte* numRef = this._field_b)
        {
            *((short*)numRef) = value;
        }
        return this._field_b;
    }

    public unsafe byte[] GetBytes(int value)
    {
        fixed (byte* numRef = this._field_c)
        {
            *((int*)numRef) = value;
        }
        return this._field_c;
    }

    public unsafe byte[] GetBytes(long value)
    {
        fixed (byte* numRef = this._field_d)
        {
            *((long*)numRef) = value;
        }
        return this._field_d;
    }

    public unsafe byte[] GetBytes(float value)
    {
        return this.GetBytes(*((int*)&value));
    }

    public unsafe byte[] GetBytes(ushort value)
    {
        fixed (byte* numRef = this._field_b)
        {
            *((short*)numRef) = (short)value;
        }
        return this._field_b;
    }

    public unsafe byte[] GetBytes(uint value)
    {
        fixed (byte* numRef = this._field_c)
        {
            *((int*)numRef) = (int)value;
        }
        return this._field_c;
    }

    public unsafe byte[] GetBytes(ulong value)
    {
        fixed (byte* numRef = this._field_d)
        {
            *((long*)numRef) = (long)value;
        }
        return this._field_d;
    }

    public bool ReadBool(BufferReader reader)
    {
        this._field_e = reader.Read(1);
        return BitConverter.ToBoolean(this._field_e.Array, this._field_e.Offset);
    }

    public byte ReadByte(BufferReader reader)
    {
        this._field_e = reader.Read(1);
        return this._field_e.Array[this._field_e.Offset];
    }

    public char ReadChar(BufferReader reader)
    {
        this._field_e = reader.Read(2);
        return BitConverter.ToChar(this._field_e.Array, this._field_e.Offset);
    }

    public double ReadDouble(BufferReader reader)
    {
        this._field_e = reader.Read(8);
        return BitConverter.ToDouble(this._field_e.Array, this._field_e.Offset);
    }

    public float ReadFloat(BufferReader reader)
    {
        this._field_e = reader.Read(4);
        return BitConverter.ToSingle(this._field_e.Array, this._field_e.Offset);
    }

    public short ReadInt16(BufferReader reader)
    {
        this._field_e = reader.Read(2);
        return BitConverter.ToInt16(this._field_e.Array, this._field_e.Offset);
    }

    public int ReadInt32(BufferReader reader)
    {
        this._field_e = reader.Read(4);
        return BitConverter.ToInt32(this._field_e.Array, this._field_e.Offset);
    }

    public long ReadInt64(BufferReader reader)
    {
        this._field_e = reader.Read(8);
        return BitConverter.ToInt64(this._field_e.Array, this._field_e.Offset);
    }

    public ushort ReadUInt16(BufferReader reader)
    {
        this._field_e = reader.Read(2);
        return BitConverter.ToUInt16(this._field_e.Array, this._field_e.Offset);
    }

    public uint ReadUInt32(BufferReader reader)
    {
        this._field_e = reader.Read(4);
        return BitConverter.ToUInt32(this._field_e.Array, this._field_e.Offset);
    }

    public ulong ReadUInt64(BufferReader reader)
    {
        this._field_e = reader.Read(8);
        return BitConverter.ToUInt64(this._field_e.Array, this._field_e.Offset);
    }
}

